/*
 * =====================================================================================
 *
 *       Filename:  limit_1024.c
 *
 *    Description:  修改进程描述符的限制
 *
 *        Version:  1.0
 *        Created:  2019年02月18日 17时27分34秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *   Organization:  
 *
 * =====================================================================================
 */

#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>


int main(int argc, char **argv)
{
    struct rlimit limit;
    getrlimit(RLIMIT_NOFILE, &limit);
    printf("Soft Limit = %ld\n", limit.rlim_cur);
    printf("Hard Limit = %ld\n", limit.rlim_max);


    limit.rlim_cur = 5000;
    setrlimit(RLIMIT_NOFILE, &limit);

    getrlimit(RLIMIT_NOFILE, &limit);
    printf("Soft Limit = %ld\n", limit.rlim_cur);
    printf("Hard Limit = %ld\n", limit.rlim_max);
    

    int cnt = 0;
    while(1) {
        int fd = open("seg", O_RDONLY);
        if(fd < 0) {
            perror("open()");
            break;
        }
        else {
            cnt++;
        }
    }
    printf("Count = %d\n", cnt);
    return 0;
}




